package com.ctgu.j13.controller;

import com.ctgu.j13.service.LoginService;
import com.ctgu.j13.vo.Workers;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class LoginController {
    @Resource
    private LoginService service;

//    public String loginMethod(@RequestParam("account") int account,@RequestParam("password") String password)
    @RequestMapping(value = "/toIndex",method = RequestMethod.POST)
    public String loginMethod(HttpServletRequest request)
    {
        String account = request.getParameter("account");
        String password = request.getParameter("password");
//        System.out.println(account);
//        System.out.println(password);
        if(account==""||password==""){
            System.out.println("用户名或密码为空，请重新输入！");
            return "login";
        }
        else
        {
            int acc = Integer.parseInt(account);
            Workers workers1=new Workers();
            workers1.setWorkerAccount(acc);
            workers1.setWorkerPassword(password);
            if(service.loginCheck(workers1))
                return "index";
        }

        return "登陆验证失败";
    }


}
